package com.platform.core.utils;

import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author libin
 */
public class RequestUtil {

    /**
     * 匹配请求路径
     *
     * @param url     路径
     * @param request 请求
     * @return boolean
     */
    public static boolean matchers(String url, HttpServletRequest request) {
        AntPathRequestMatcher matcher = new AntPathRequestMatcher(url);
        return matcher.matches(request);
    }

    /**
     * 匹配请求路径
     *
     * @param list    路径列表
     * @param request 请求
     * @return boolean
     */
    public static boolean matchesUrls(List<String> list, HttpServletRequest request) {
        return list.parallelStream().anyMatch(url -> matchers(url, request));
    }
}
